package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysMenu;
import io.mybatis.example.springboot.service.SysMenuService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_menu - 菜单权限表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysMenus")
public class SysMenuController {

  @Autowired
  private SysMenuService sysMenuService;

  @PostMapping
  public DataResponse<SysMenuDO> save(@RequestBody SysMenuDO sysMenu) {
    return DataResponse.ok(sysMenuService.save( sysMenu));
  }

  @GetMapping
  public RowsResponse<SysMenuDO> findList(@RequestBody SysMenuDO sysMenu) {
    return RowsResponse.ok(sysMenuService.findList( sysMenu));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysMenuDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysMenuService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysMenuDO> update(@PathVariable("id") Long id, @RequestBody SysMenuDO sysMenu) {
    sysMenu.setId(id);
    return DataResponse.ok(sysMenuService.update( sysMenu));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysMenuService.deleteById(id) == 1);
  }

}
